package com.javakc.platform.modules.system.attachment.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javakc.platform.modules.system.logger.component.annotation.LoggerOperation;
import com.javakc.platform.modules.system.logger.component.enumerate.LoggerEnumerate;
import com.javakc.platform.modules.system.attachment.entity.SystemAttachment;
import com.javakc.platform.modules.system.attachment.service.SystemAttachmentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Collection;

/**
* @author zhouhonggang
* @version 1.0.0
* @project springboot-development-platform
* @datetime 2022-04-16
* @description: [系统-附加·接口]
*/
@RestController
@RequestMapping("/attachment/system-attachment")
public class SystemAttachmentController {

    @Resource
    private SystemAttachmentService systemAttachmentService;

    /**
     * 系统-附加 添加
     * @param entity 实体类
     */
    @PostMapping
    @LoggerOperation(module = "系统-附加", message = "添加", type = LoggerEnumerate.INSERT)
    public void save(@Valid @RequestBody SystemAttachment entity) {
        systemAttachmentService.save(entity);
    }

    /**
     * 系统-附加 修改
     * @param entity 实体类
     */
    @PutMapping
    @LoggerOperation(module = "系统-附加", message = "修改", type = LoggerEnumerate.UPDATE)
    public void update(@Valid @RequestBody SystemAttachment entity) {
        systemAttachmentService.updateById(entity);
    }

    /**
     * 系统-附加 单删
     * @param id 主键id
     */
    @DeleteMapping("{id}")
    @LoggerOperation(module = "系统-附加", message = "单删", type = LoggerEnumerate.DELETE)
    public void delete(@NotNull(message = "主键ID不能为null") @PathVariable int id) {
        systemAttachmentService.removeById(id);
    }

    /**
     * 系统-附加 批删
     * @param ids 主键id集合
     */
    @DeleteMapping
    @LoggerOperation(module = "系统-附加", message = "批删", type = LoggerEnumerate.DELETE)
    public void delete(@RequestBody @NotEmpty(message = "主键ID不能为null") Collection<Integer> ids) {
        systemAttachmentService.removeByIds(ids);
    }

    /**
     * 系统-附加 主键ID查询
     * @param id 主键id
     * @return 实体类
     */
    @GetMapping("{id}")
    @LoggerOperation(module = "系统-附加", message = "主键查询", type = LoggerEnumerate.SELECT)
    public SystemAttachment load(@PathVariable @NotNull(message = "主键ID不能为null") int id) {
        return systemAttachmentService.getById(id);
    }

    /**
     * 系统-附加 分页查询
     * @param entity 主键对象
     * @return 分页对象
     */
    @PostMapping("page")
    @LoggerOperation(module = "系统-附加", message = "分页查询", type = LoggerEnumerate.SELECT)
    public Page<SystemAttachment> page(@RequestBody SystemAttachment entity) {
        return systemAttachmentService.page(entity);
    }

}